// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Jeff Stewart
//
// Extracts information from the localhost, including timezone, time,
// locale information, operating system details, etc.

#ifndef POPDIAG_PROBES_LOCALHOST_H__
#define POPDIAG_PROBES_LOCALHOST_H__

#include <QtCore/QString>
#include <QtCore/QTextStream>

#include "probes/probe.h"

namespace popdiag {

// Extract information from the local machine for reporting
// in the logs.
class LocalHostProbe : public Probe {
 public:
  LocalHostProbe();

  // Retrieve a numeric representation of this fault.
  // 0 is reserved for "success".  Most other values are probe-specific.
  // This probe never fails.
  inline int GetFaultId() { return 0; }

  // Get a string representation of this probe's class.
  // Can be used with GetFaultId() to construct support urls, though
  // it is not currently used for this.
  inline QString GetProbeId() { return "Localhost"; }

  // Fetch progress made in this probe.
  void GetProgress(int *completed, int *estimated_total) {
    *completed = executed_ ? 1 : 0;
    *estimated_total = 1;
  }

  // Get a display string describing the results of this probe.
  inline QString GetDisplayText() {
    return tr("Succeeded", "Generic success description");
  }

  // Starts the probe.  Called by the base class.
  virtual void StartProbe();
 private:
  static QString FormatOffsetInMinutes(int minutes);

  void LogHostnameAndIP();
  void LogTime();
  void LogTimeZone();

  // These methods are implemented in the per-OS localhost_<platform> files.

  // Return the offset to be applied to GMT to arrive at local time.
  int GetOffsetFromGMTInMinutes();

  // Return a human-readable representation of the timezone,
  // preferably in English.
  QString GetTimezoneName();

  void LogOSVersion();
  void LogLocale();
  bool executed_;
};

}  // namespace popdiag

#endif  // POPDIAG_PROBES_LOCALHOST_H__
